home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / updates / update24.zoo / gdbm / diffs2 next >
Text File  |  1992-08-13  |  5KB  |  186 lines

  1. *** 1.2    1992/04/07 21:55:43
  2. --- gdbmreorg.c    1992/08/14 03:18:41
  3. ***************
  4. *** 24,29 ****
  5. --- 24,32 ----
  6.                   Western Washington University
  7.                   Bellingham, WA 98226
  8.           phone:  (206) 676-3035
  9. +     Cache and walking file descriptor patch applied
  10. +     e-mail: phil@compnews.co.uk
  11.          
  12.   ************************************************************************/
  13.   
  14. ***************
  15. *** 74,79 ****
  16. --- 77,83 ----
  17.     gdbm_file_info *new_dbf;        /* The new file. */
  18.     char *new_name;            /* A temporary name. */
  19.     int  len;                /* Used in new_name construction. */
  20. +   int new_desc;                /* Used to avoid walking file desc */
  21.     datum key, nextkey, data;        /* For the sequential sweep. */
  22.     struct stat fileinfo;            /* Information about the file. */
  23.     int  index;                /* Use in moving the bucket cache. */
  24. ***************
  25. *** 112,118 ****
  26.     if (new_dbf == NULL)
  27.       {
  28.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  29. !       free (new_name);
  30.         return -1;
  31.       }
  32.   
  33. --- 116,122 ----
  34.     if (new_dbf == NULL)
  35.       {
  36.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  37. !       free (new_name);    /* free up the space allocated to new_name */
  38.         return -1;
  39.       }
  40.   
  41. ***************
  42. *** 131,138 ****
  43.             gdbm_close (new_dbf);
  44.             gdbm_errno = GDBM_REORGANIZE_FAILED;
  45.             unlink (new_name);
  46.             return -1;
  47. !         };
  48.        }
  49.         else
  50.        {
  51. --- 135,143 ----
  52.             gdbm_close (new_dbf);
  53.             gdbm_errno = GDBM_REORGANIZE_FAILED;
  54.             unlink (new_name);
  55. +           free(new_name);    /* free up the space allocated to new_name */
  56.             return -1;
  57. !         }
  58.        }
  59.         else
  60.        {
  61. ***************
  62. *** 140,145 ****
  63. --- 145,151 ----
  64.         gdbm_close (new_dbf);
  65.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  66.         unlink (new_name);
  67. +       free(new_name);    /* free up the space allocated to new_name */
  68.         return -1;
  69.        }
  70.         nextkey = gdbm_nextkey (dbf, key);
  71. ***************
  72. *** 154,159 ****
  73. --- 160,167 ----
  74.       {
  75.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  76.         gdbm_close (new_dbf);
  77. +       unlink (new_name);
  78. +       free(new_name);        /* free up the space allocated to new_name */
  79.         return -1;
  80.       }
  81.   #endif
  82. ***************
  83. *** 160,172 ****
  84.   
  85.     /* Fix up DBF to have the correct information for the new file. */
  86.     UNLOCK_FILE(dbf);
  87. !   close (dbf->desc);
  88.   #ifdef atarist
  89.     close(new_dbf->desc);
  90.     if (rename (new_name, dbf->name) != 0)
  91.       {
  92.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  93.         gdbm_close (new_dbf);
  94.         return -1;
  95.       }
  96.     if((new_dbf->desc = open(dbf->name, O_RDWR)) < 0)
  97. --- 168,198 ----
  98.   
  99.     /* Fix up DBF to have the correct information for the new file. */
  100.     UNLOCK_FILE(dbf);
  101. ! #ifndef atarist
  102. !   /* phil - don't close the descriptor, dup it... */
  103. !   /* close (dbf->desc); */
  104. !   if ((new_desc = dup2(new_dbf->desc, dbf->desc)) < 0)
  105. !     {
  106. !       gdbm_close(new_dbf);
  107. !       gdbm_errno = GDBM_REORGANIZE_FAILED;
  108. !       unlink (new_name); /* unlink the created file */
  109. !       free(new_name);        /* free up the space allocated to new_name */
  110. !       return -1;
  111. !     }
  112. !   /* ...and reassign */
  113. !   dbf->desc = new_desc;
  114. ! #endif
  115.   #ifdef atarist
  116. +   close (dbf->desc);
  117.     close(new_dbf->desc);
  118.     if (rename (new_name, dbf->name) != 0)
  119.       {
  120.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  121.         gdbm_close (new_dbf);
  122. +       unlink(new_name);
  123. +       free(new_name);        /* free up the space allocated to new_name */
  124.         return -1;
  125.       }
  126.     if((new_dbf->desc = open(dbf->name, O_RDWR)) < 0)
  127. ***************
  128. *** 173,178 ****
  129. --- 199,205 ----
  130.       {
  131.         gdbm_errno = GDBM_REORGANIZE_FAILED;
  132.         gdbm_close (new_dbf);
  133. +       free(new_name);        /* free up the space allocated to new_name */
  134.         return -1;
  135.       }
  136.       lseek(new_dbf->desc, 0L, SEEK_END);
  137. ***************
  138. *** 188,199 ****
  139.       free (dbf->bucket_cache[index].ca_data.dptr);
  140.       }
  141.   
  142. !   dbf->desc           = new_dbf->desc;
  143.     dbf->header         = new_dbf->header;
  144.     dbf->dir            = new_dbf->dir;
  145.     dbf->bucket         = new_dbf->bucket;
  146.     dbf->bucket_dir     = new_dbf->bucket_dir;
  147. !   dbf->cache_entry    = new_dbf->cache_entry;
  148.     dbf->last_read      = new_dbf->last_read;
  149.     for (index = 0; index < CACHE_SIZE; index++)
  150.       dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
  151. --- 215,234 ----
  152.       free (dbf->bucket_cache[index].ca_data.dptr);
  153.       }
  154.   
  155. ! #ifndef atarist
  156. !   /* dbf->desc           = new_dbf->desc; - now dup */
  157. ! #else
  158. !   dbf->desc           = new_dbf->desc;  /* the newly opened file */
  159. ! #endif
  160.     dbf->header         = new_dbf->header;
  161.     dbf->dir            = new_dbf->dir;
  162.     dbf->bucket         = new_dbf->bucket;
  163.     dbf->bucket_dir     = new_dbf->bucket_dir;
  164. !   /* phil - do not assign the cache, it will/may be different... */
  165. !   /* dbf->cache_entry    = new_dbf->cache_entry; */
  166. !   /* use the new cache */
  167. !   dbf->cache_entry    = &dbf->bucket_cache[new_dbf->last_read];
  168.     dbf->last_read      = new_dbf->last_read;
  169.     for (index = 0; index < CACHE_SIZE; index++)
  170.       dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
  171. ***************
  172. *** 206,211 ****
  173. --- 241,248 ----
  174.   
  175.     /* Make sure the new database is all on disk. */
  176.     fsync (dbf->desc);
  177. +   free(new_name);        /* free up space allocated to new name */
  178.   
  179.     return 0;
  180.   }
  181.